//
//  EAGLView.h
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 12/03/12.
//  Copyright (c) 2012 UIT. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
class LBTexture;
//#include "LBTexture.h"
/*
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
The view content is basically an EAGL surface you render your OpenGL scene into.
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/

@protocol EAGLViewDelegate;

@interface EAGLView : UIView {
    
@private
    /* The pixel dimensions of the backbuffer */
    GLint backingWidth;
    GLint backingHeight;
  
    EAGLContext *context;
  
    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
  GLuint viewRenderbuffer, viewFramebuffer;
  
    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
    GLuint depthRenderbuffer;
  
    NSTimer *animationTimer;
    NSTimeInterval animationInterval;
    
    CGRect imageRect;                       //rect of image will show to screen
    id<EAGLViewDelegate> delegate;
    UIImage* inputImg;
    bool isUseSmoothSkin;
    int effectIndex;
    int frameIndex;
    bool isAllowCrop;
    bool isNeedRenderFrameFilter;
    
    LBTexture** frameTextures;
    
}

@property NSTimeInterval animationInterval;
@property (readonly) CGRect imageRect;
@property (readonly) float scaleFinal;
@property (assign)id<EAGLViewDelegate> delegate;
@property (nonatomic, retain) UIImage* inputImg;
@property (nonatomic) bool isUseSmoothSkin;
@property (nonatomic) int frameIndex;
@property (nonatomic, readonly) bool isAllowCrop;

- (void)startAnimation;
- (void)stopAnimation;
- (void)drawView;
- (void)loop;
- (void)update;

- (void) viewportX: (int)x y:(int)y width:(int) width height:(int) height andScreenSizeWidth:(int) widthScreen screenSizeHeight:(int)heightScreen;
- (void) effect:(int) index;
- (LBTexture*) outputTexture;
- (CGRect)imageRectByParentOfParent;
- (void)rotate;
- (void)saveImageFinalTo:(NSString*)filePath rect:(CGRect) cropRect;
- (void)saveImageFinalTo:(NSString*)filePath;
- (CGRect)imageRectReal;
- (void)dealloc;
- (void)inputImage:(UIImage*)image isFirstTime:(bool)isFristTime;
- (void)updateOpenGLSize;
-(void)deleteOpenGLData;
- (bool)isFaceDetected;
- (void) setStandardBrightness:(float)standardBrightness;
- (void) setBlurSize:(float)blurSize;
- (void) renderFilter;
- (float) blurSizeOfBeautifulFilter;
- (void) setSharpness:(float)sharpness;
- (void) applySmoothSkinValue;
- (void) updateCropRect:(CGRect)cropRect;
- (UIImage*) getOriginImage;
- (UIImage*) getOutputImage;
- (void)inputNoResetImage:(UIImage*)image;

@end



@protocol EAGLViewDelegate <NSObject>

@optional
- (void)didFinishRotate:(id)sender;
- (void)shouldFaceDetection:(id)sender;
- (void)didFaceDetection:(id)sender;
- (void)eaglViewTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
@end
